home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8202 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.microsoft.com!news
  2. From: a-cnadc@microsoft.com (Dann Corbit)
  3. Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland
  4. Subject: Re: Tough FACTORIAL math problem...
  5. Date: 15 Feb 1996 18:42:31 GMT
  6. Organization: Microsoft Corporation
  7. Message-ID: <4fvuqn$2hk@news.microsoft.com>
  8. References: <4fr8be$ass@news.iconn.net>
  9. NNTP-Posting-Host: 157.57.171.202
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.14
  12.  
  13. In article <4fr8be$ass@news.iconn.net>, thecrow@iconn.net says...
  14. >
  15. >Here is what I am trying to do, I want to find the last NON-ZERO digit of a 
  16. >given factorial.  For instance,
  17. >
  18. >5! = 120
  19. >
  20. >so the last non-zero digit is 2.  I want to be able to do this up to 1000.  
  21. >Problem is, no matter how huge of a data-type you use, there isn't any way for 
  22. >the computer to handle 1000!, it is however possible to find the last non-zero 
  23. >digit somehow.  One thing I have tried is as I went through mulitplying the 
  24. >series of numbers in the factorial (5 * 4 * 3 * 2) I would remove all the 
  25. >trailing ZEROS, I got this to work up to 789, but it wont work with 1000 and i 
  26. >am not really sure why.  If anyone has a clue how I can do this let me know.
  27.  
  28. Actually, long double on INTEL or HFLOAT on the VAX will handle 1754!.
  29.  
  30. If you just want to find the final digit, after each multiplication, remove the
  31. trailing digits by dividing by ten.  Then take a modulus with ten.  The final 
  32. digit is going to be the result of the product of the two least significant
  33. digits.
  34. -- 
  35. The opinions expressed in this message are my own personal views 
  36. and do not reflect the official views of Microsoft Corporation.
  37.  
  38.